
TARGET		:= $(shell pwd | sed "s/^.*\///")

CFLAGS		:= -Wall -pipe -O2
SRCS		:= $(foreach DIR, ., $(wildcard $(DIR)/*.c))

OBJS		:= $(SRCS:.c=.o)		# object files
DEPS		:= $(SRCS:.c=.d)		# depend files

%.o : %.c
	$(CC) $(CFLAGS) -c $< -o $@

%.o : %.cpp
	$(CXX) $(CFLAGS) -c $< -o $@

%.d : %.c	# make dependency file
	@$(CC) -MM -MP $(CPPFLAGS) $< | sed 's/\($(notdir $*)\)\.o[ :]*/$(subst /,\/,$(dir $*))\1.o $(subst /,\/,$@) : /g' > $@; [ -s $@ ] || rm -f $@

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^ $(INC) $(LIBS)

clean :
	rm -f $(TARGET) $(OBJS)

distclean : clean
	rm -f $(DEPS)

#ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
#endif

